package com.dbutils;

import java.sql.*;

public class DbInit {
    private static String CLASSNAME="org.mariadb.jdbc.Driver";
    private static String URL="jdbc:mariadb://localhost:3306/sspu";
    private static String USERNAME="root";
    private static String PASSWORD="123456";


    public Connection getConnection(){
         Connection connection;
        try {
            Class.forName(CLASSNAME);
             connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);
            return  connection;
        } catch (Exception e) {
            e.printStackTrace();
        }
     return null;

    }

    public void closeConnection(Connection connection,PreparedStatement ps){
        try {
            if(connection!=null){
                connection.close();
            }

            if(ps!=null){
                ps.close();
            }

        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

    }



    public void closeConnection(Connection connection, ResultSet rs, PreparedStatement ps){
        try {
             closeConnection(connection,ps);

            if(rs!=null){
                rs.close();
            }


        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

    }

}
